package com.renu.jdependencyanalyser.core;

import com.renu.jdependencyanalyser.model.*;

import com.renu.jdependencyanalyser.utils.MavenUtil;
import com.renu.jdependencyanalyser.utils.MyProjectUtil;

import java.util.*;

public class JarBorderGene {

    private ProjectInfo projectInfo;
    private Set<String> borderJars ;

    private JarNode jarNode;



    public JarBorderGene(ProjectInfo projectInfo) {
        this.projectInfo = projectInfo;
        this.borderJars = calBorderJars();

        this.jarNode = MavenUtil.getDependencyRoot(MyProjectUtil.projectBasePath );
    }

    public JarNode getDependencyNode() {
        return jarNode;
    }

    private Set<String> calBorderJars() {
        HashSet<String> resSet = new HashSet<>();
        Map<String, ClassModel> outerClassMap = projectInfo.getOuterClassMap();
        Map<String, PackageModel> outerPckMap = projectInfo.getOuterPckMap();

        Map<String, ClassModel> borderClassMap = projectInfo.getBorderClassMap();
        for (String classSig : borderClassMap.keySet()) {
            String pckSig = outerClassMap.get(classSig).getPck();
            String jarSig = outerPckMap.get(pckSig).getJarSig();
            JarModel jarModel = projectInfo.getJarModelMap().get(jarSig);
            projectInfo.getBorderJarMap().put(jarSig,jarModel);
            resSet.add(jarSig);
        }


        return resSet;

    }

    public Set<String> getBorderJars() {
        return borderJars;
    }


}
